#ifndef CARDGROUP_H
#define CARDGROUP_H
#include "flowlayout.h"
#include "cardview.h"
#include <QPainterPath>  // 添加路径缓存需要的头文件
class CardGroup : public QWidget
{
    Q_OBJECT
public:
    explicit CardGroup(QWidget *parent = nullptr);
    ~CardGroup();
    void addCardView(CardView* cardView);
    CardView* getCardView(const QString& str);
    FlowLayout* layout() const { return m_flowLayout; }
    // 优化：添加属性变更检查避免无效重绘
    void setBorderRadius(int radius);
    void setBorderColor(const QColor &color);
    void setBorderWidth(int width);
    void setBackgroundColor(const QColor &color);
protected:
    void paintEvent(QPaintEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;  // 添加resize事件处理
private:
    void updatePainterPath();  // 添加路径更新方法
    FlowLayout *m_flowLayout;
    int m_borderRadius;
    QColor m_borderColor;
    int m_borderWidth;
    QColor m_backgroundColor;
    QHash<QString, CardView*> m_cardMap;

    // 优化：添加路径缓存
    QPainterPath m_cachedPath;
    QRect m_lastPathRect;  // 记录上次计算路径时的控件大小
};
#endif // CARDGROUP_H
